package com.example.mvvmapplication.domain

import com.example.mvvmapplication.api.ApiException

/**
 *
 * @ClassName:      ResultData$
 * @Description:    java类作用描述
 * @Author:         xinya
 * @CreateDate:     2020/11/3$ 17:03$
 * @UpdateRemark:   更新内容
 * @Version:        1.0
 */
data class ResultData<T>(
    val success: Boolean,
    val code: Int,
    val message: String,
    val data: T
) {
    companion object {
        const val CODE_SUCCESS = 10000
    }

    fun apiData(): T {
        if (code == CODE_SUCCESS) {
            return data
        } else {
            throw ApiException(code, message)
        }
    }
}